<template>
	<view class="Withdrawal">
		<view class="message_top">
			<view class="message_top_title" :style="{top:computedTop}">充值</view>
			<view class="message_top_back" :style="{top:computedTop}" @click="Back">
				<image src="../../static/search/back.png" class="bfbimages"></image>
			</view>
		</view>

		<view class="Withdrawal_box">
			<view class="Withdrawal_box_box">
				<view>
					<text>充值金额</text>
					<view>
						<text style="font-size: 52rpx;color: #11182F;">￥</text>
						<input type="text" style="font-size: 32rpx;color: #11182F;font-weight: bold;width: 470rpx;"
							placeholder="请输入" v-model="recharge_money" />
						<text style="font-size:26rpx;color: #FE4926;"></text>
					</view>
				</view>
				<view><text style="font-size: 22rpx;color: #11182F;">支付即阅读并同意<text
							style="color: #FE4825;">《增值服务与自动续费服务》</text></text></view>
				<view @click="Ok">确认充值</view>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menuButtonInfo: null,
				recharge_money: ''
			}
		},
		computed: {
			computedTop() {
				if (this.menuButtonInfo) {
					return `${this.menuButtonInfo.height * 2 - 6}px`;
				}
				return '0px';
			},
		},
		onLoad() {
			const info = uni.getMenuButtonBoundingClientRect();
			this.menuButtonInfo = info;
		},
		methods: {
			Ok() {
				let data = {
					recharge_money: this.recharge_money
				}
				this.$request('/api/pay/recharge', data).then((res) => {
					console.log(res.data, '充值');
					uni.requestPayment({
						provider: 'wxpay',
						orderInfo: '',
						appId: res.data.appId,
						nonceStr: res.data
							.nonceStr, //随机字符*//串，长度为32个字符以下。
						timeStamp: res.data.timeStamp, //时间戳，要字符串类型的
						package: res.data
							.package, //prepay_id 参数值，提交格式如：prepay_id=xx
						signType: res.data.signType, //MD5类型
						paySign: res.data.paySign, //签名
						success: function(res) {
							this.recharge_money=''
							//支付成功的回调    成功之后你想做什么在这里操作  比如弹窗一个提示:支付成功等
							uni.showToast({
								title: '充值成功',
								icon: 'none',
								duration: 1500
							});
							setTimeout(() => {
								uni.navigateBack()
							}, 1500)
						},

					});
				})
			},
			Back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.Withdrawal {
		width: 100vw;
		height: 100vh;
		float: left;

		.message_top {
			width: 100%;
			height: 230rpx;
			position: relative;
			background-color: #FFE9D4;

			.message_top_title {
				width: 100%;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #333333;
				position: absolute;
				left: 0;
				z-index: 2;
			}

			.message_top_back {
				width: 44rpx;
				height: 44rpx;
				position: absolute;
				left: 30rpx;
				z-index: 9;
			}
		}

		.Withdrawal_box {
			width: 100%;
			height: calc(100vh - 230rpx);
			position: relative;

			.Withdrawal_box_box {
				width: 100%;
				height: 100%;
				position: absolute;
				left: 0;
				top: -30rpx;
				border-top-right-radius: 30rpx;
				border-top-left-radius: 30rpx;
				background-color: #FFFFFF;
				z-index: 6;
				float: left;
			}

			.Withdrawal_box_box>view:nth-child(1) {
				width: 610rpx;
				margin: 62rpx auto 0;
			}

			.Withdrawal_box_box>view:nth-child(1)>text:nth-child(1) {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
			}

			.Withdrawal_box_box>view:nth-child(1)>view {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				height: 100rpx;
				border-bottom: 2rpx solid #000000;
				margin: 5rpx auto 0;
			}

			.Withdrawal_box_box>view:nth-child(2) {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 120rpx auto 0;
			}

			.Withdrawal_box_box>view:nth-child(3) {
				width: 610rpx;
				height: 100rpx;
				background: linear-gradient(270deg, #FE4624 0%, #FF8143 100%);
				border-radius: 60rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #FFFFFF;
				text-align: center;
				line-height: 100rpx;
				margin: 20rpx auto 0;
			}
		}
	}
</style>